package com.yanqu.road.server.pb;

import com.yanqu.road.entity.config.match.MatchReward;
import com.yanqu.road.pb.variety.VarietyProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;

import java.util.List;

/**
 * @author ：zfr
 * @date ：2021/2/6 14:48
 */
public class VarietyPb {
    public static VarietyProto.DispatchTeamCrossReqMsg.Builder parseDispatchReq(int id, int level, int occupation, int matchId, List<Integer> patronsIds, GamePlayer player) {
        VarietyProto.DispatchTeamCrossReqMsg.Builder builder = VarietyProto.DispatchTeamCrossReqMsg.newBuilder();
        builder.setId(id);
        builder.setLevel(level);
        builder.setOccapution(occupation);
        builder.setMatchId(matchId);
        PatronsModule module = player.getModule(PatronsModule.class);
        for (Integer patronsId : patronsIds) {
            VarietyProto.PatronsTemp.Builder temp = VarietyProto.PatronsTemp.newBuilder();
            temp.setPatronsId(patronsId);
            temp.setEarnSpeed(module.getUserPatrons(patronsId).getAbility().longValue());
            builder.addPatrons(temp);
        }
        builder.setPlayerBaseData(PlayerPb.parsePlayerBaseTempMsg(player.getUserInfo()));
        return builder;
    }

    public static VarietyProto.VarietyReward.Builder parseVarietyReward(VarietyProto.VarietyMyRank myRank, MatchReward reward) {
        VarietyProto.VarietyReward.Builder builder = VarietyProto.VarietyReward.newBuilder();
        builder.setLevel(myRank.getLevel());
        builder.setType(myRank.getType());
        builder.setMatchId(myRank.getMatchId());
        builder.setId(myRank.getId());
        builder.addAllPatronsId(myRank.getPatronsIdList());
        builder.setPatronsReward(reward.getPatronsRewards());
        builder.setReward(reward.getPlayerRewards());
        builder.setMyRank(myRank.getIndex());
        return builder;
    }
}
